﻿using System;
using System.Collections;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.Xml.Linq;
using System.Web.SessionState;

namespace YXShop.Web.filehandle
{
    /// <summary>
    /// $codebehindclassname$ 的摘要说明
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    public class product_sendgroupbuy_form : IHttpHandler, IRequiresSessionState 
    {

        public void ProcessRequest(HttpContext context)
        {
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            string Name = string.Empty;
            int UID = 0;
            if (context.Session["MemberID"] != null)
            {
                Name = context.Session["MemberName"].ToString();
                UID = Convert.ToInt32(context.Session["MemberID"].ToString());
            }
            else
            {
                ChangeHope.WebPage.Script.Alert("您未登陆或注册。");
                ChangeHope.WebPage.Script.GoBack();
            }
            int productid = ChangeHope.WebPage.PageRequest.GetFormInt("hfProductID");
            if (productid < 0)
            {
                ChangeHope.WebPage.Script.Alert("对不起发起团购失败");
                ChangeHope.WebPage.Script.GoBack();
            }

            YXShop.BLL.Product.Product_SendGroupBuyInfo pgbbll = new YXShop.BLL.Product.Product_SendGroupBuyInfo();
            YXShop.Model.Product.Product_SendGroupBuyInfo pgbmodel = new YXShop.Model.Product.Product_SendGroupBuyInfo();

            pgbmodel.Name = ChangeHope.WebPage.PageRequest.GetFormString("txtName");
            pgbmodel.UID = UID;
            pgbmodel.ProductID = productid;
            pgbmodel.BuyCount = 0;
            pgbmodel.Deposit = 0;
            pgbmodel.Address = ChangeHope.WebPage.PageRequest.GetFormString("txtAddress");
            pgbmodel.Title = ChangeHope.WebPage.PageRequest.GetFormString("txtTitle");
            pgbmodel.Synopsis = ChangeHope.WebPage.PageRequest.GetFormString("txtSynopsis");
            pgbmodel.Content = ChangeHope.WebPage.PageRequest.GetFormString("txtContent");

            ChangeHope.Common.UploadFile uf = new ChangeHope.Common.UploadFile();
            uf.ExtensionLim = ".gif,.jpg,.jpeg,.bmp";
            uf.FileLengthLim = 4000;
            uf.MyFile = context.Request.Files[0];
            uf.SavePath = "\\yxuploadfile\\groupbuy";
            if (uf.HTMLUpLoad())
            {
                pgbmodel.Images = uf.FilePath;
            }
            else
            {
                ChangeHope.WebPage.Script.Alert("操作失败，" + uf.Message + "");
                ChangeHope.WebPage.Script.GoBack();
            }
            pgbmodel.State = 0;
            pgbmodel.CreateTime = System.DateTime.Now;
            pgbmodel.CreateIP = System.Web.HttpContext.Current.Request.UserHostAddress;
            pgbmodel.ActivityStartTime =Convert.ToDateTime(ChangeHope.WebPage.PageRequest.GetFormString("txtActivityTime"));
            pgbmodel.ActivityEndTime = Convert.ToDateTime(ChangeHope.WebPage.PageRequest.GetFormString("txtEndActivityTime"));
            pgbmodel.ActivityQQ = ChangeHope.WebPage.PageRequest.GetFormString("txtQQ");
            pgbmodel.Tel = ChangeHope.WebPage.PageRequest.GetFormString("txtTel");
            pgbmodel.IDCard = ChangeHope.WebPage.PageRequest.GetFormString("txtidcard");
            pgbmodel.SignupNumber = 0;
            pgbmodel.WithSignUpNumber = 0;

            if (pgbbll.Add(pgbmodel) != 0)
            {
                string url = YXShop.TemplateAction.Common.UrlStr("product_groupbuy_content", "q_productid=" + productid + "","product/");
                ChangeHope.WebPage.Script.AlertAndRedirect("恭喜您，发起团购成功，待审核。", url);
            }
            else
            {
                ChangeHope.WebPage.Script.Alert("操作失败，发起团购出现异常！");
            }
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}
